package com.yuezhu.fragment;

import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.AppCompatSpinner;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.yuezhu.Model.DictionaryModel;
import com.yuezhu.Model.PlanModel;
import com.yuezhu.R;
import com.yuezhu.activity.MyprojectActivity;
import com.yuezhu.been.DataChangedEvent;
import com.yuezhu.been.UserMsg;
import com.yuezhu.constante.BusAction;
import com.yuezhu.constomview.DragView;
import com.yuezhu.constomview.DragViewGroups;
import com.yuezhu.control.TaskEngine;
import com.yuezhu.global.ApplicationContext;
import com.yuezhu.global.BaseFragment;
import com.yuezhu.util.LogUtils;
import com.yuezhu.util.LoginOut;
import com.yuezhu.util.MyToast;
import com.yuezhu.util.StringUtil;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class PartitionnformationFragment extends BaseFragment implements View.OnClickListener {
    //    //显示的数组
//    final String arr1[] = new String[]{
//            "办公",
//            "酒店",
//            "住宅",
//            "住宅"
//
//    };
    private ArrayList<String> arr1 = new ArrayList<>();
    private ArrayList<String> arr2 = new ArrayList<>();
    @InjectView(R.id.spinner2)
    AppCompatSpinner spinner2;
    @InjectView(R.id.dragview)
    DragView dragview;
    int screen_height = ApplicationContext.getInstance().getScreen_height();
    @InjectView(R.id.drag_groups)
    DragViewGroups dragGroups;
    @InjectView(R.id.iv_bottome_left)
    ImageView ivBottomeLeft;
    @InjectView(R.id.iv_bottome_middle)
    ImageView ivBottomeMiddle;
    @InjectView(R.id.iv_bottome_right)
    ImageView ivBottomeRight;
    @InjectView(R.id.part_information_name)
    TextView partInformationName;
    @InjectView(R.id.information_spinner)
    AppCompatSpinner informationSpinner;
    @InjectView(R.id.fenqu_text1)
    TextView fenquText1;
    @InjectView(R.id.fenqu_text2)
    TextView fenquText2;
    @InjectView(R.id.fenqu_text3)
    TextView fenquText3;
    @InjectView(R.id.fenqu_text4)
    TextView fenquText4;
    @InjectView(R.id.jiben_name)
    EditText jibenName;
    @InjectView(R.id.line1_left)
    TextView line1_left;
    @InjectView(R.id.line1_middle)
    EditText line1_middle;
    @InjectView(R.id.line1_right)
    TextView line1_right;
    @InjectView(R.id.line2_left)
    TextView line2_left;
    @InjectView(R.id.line2_middle)
    EditText line2_middle;
    @InjectView(R.id.line2_right)
    TextView line2_right;
    @InjectView(R.id.line3_left)
    TextView line3_left;
    @InjectView(R.id.line3_middle)
    EditText line3_middle;
    @InjectView(R.id.line3_right)
    TextView line3_right;
    @InjectView(R.id.checkbox)
    CheckBox checkbox;
    @InjectView(R.id.notice)
    View notice;
    @InjectView(R.id.bottom_bar)
    View bottom_bar;
    private PlanModel planModel;
    public static ArrayList<PlanModel.Area> areaArrayListOfPlan;
    public static ArrayList<PlanModel.Area> areaArrayList_Copy;
    private ArrayList<TextView> textViews = new ArrayList<TextView>();
    private AlertDialog dialog;
    public static int CURRENT_PLAN = -1;

    @Override
    public void initview(View view) {

    }

    private void initSpinner(String typeName) {
        arr2 = DictionaryModel.getInstance().getTypeNameList();
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), R.layout.simple_spinner_item2, arr2) {
            @Override
            public View getDropDownView(int position, View convertView,
                                        ViewGroup parent) {
                View view = LayoutInflater.from(getContext()).inflate(R.layout.item_spinner2, null);
                TextView label = (TextView) view.findViewById(R.id.spinner_item_label);
                label.setText(arr2.get(position));
                return view;
            }
        };
        spinner2.setAdapter(arrayAdapter);
        spinner2.setSelection(arr2.indexOf(typeName));
        spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                spinner2.setDropDownVerticalOffset(spinner2.getHeight());
                areaArrayListOfPlan.get(currentIndex).type = DictionaryModel.getInstance().getTypeIDByTypeNmae(spinner2.getSelectedItem().toString());
                setData(areaArrayListOfPlan.get(currentIndex));
            }

            @Override
            public void onNothingSelected(AdapterView<?> adapterView) {

            }
        });
        if (UserMsg.getInstance().getLevel() == 0) {
            spinner2.setEnabled(false);
        } else {
            spinner2.setEnabled(true);
        }
    }

    @Override
    public void setLiseners() {
        ivBottomeLeft.setOnClickListener(this);
        ivBottomeRight.setOnClickListener(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = getActivity().getLayoutInflater().inflate(R.layout.activity_partitionnformation, null);
        ButterKnife.inject(this, view);
        setLiseners();
        ivBottomeLeft.setImageResource(R.drawable.message_left);
        ivBottomeRight.setImageResource(R.drawable.message_right);
        setParm();
        init2();
        checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                dragGroups.setSkyLobby(currentIndex, b);
                areaArrayListOfPlan.get(currentIndex).setIsSkyLobby(b);
            }
        });
        EventBus.getDefault().register(this);
        line1_middle.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    areaArrayListOfPlan.get(currentIndex).floorValue = Integer.parseInt(line1_middle.getText().toString());
                } catch (Exception e) {

                }
            }
        });
        line2_middle.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    areaArrayListOfPlan.get(currentIndex).targetPerson = Integer.parseInt(line2_middle.getText().toString());
                } catch (Exception e) {

                }
            }
        });
        line3_middle.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    areaArrayListOfPlan.get(currentIndex).persionRatio = Integer.parseInt(line3_middle.getText().toString());
                } catch (Exception e) {

                }
            }
        });
        jibenName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {
                try {
                    textViews.get(currentIndex).setText(jibenName.getText());
                    dragGroups.setFenquText(jibenName.getText().toString(), currentIndex);
                    areaArrayListOfPlan.get(currentIndex).areaName = jibenName.getText().toString();
                } catch (Exception e) {

                }
            }
        });
        if (UserMsg.getInstance().getLevel() == 0) {
            notice.setVisibility(View.VISIBLE);
            bottom_bar.setVisibility(View.GONE);
            line1_middle.setEnabled(false);
            line2_middle.setEnabled(false);
            line3_middle.setEnabled(false);
        } else {
            notice.setVisibility(View.INVISIBLE);
            bottom_bar.setVisibility(View.VISIBLE);
            line1_middle.setEnabled(true);
            line2_middle.setEnabled(true);
            line3_middle.setEnabled(true);
        }
        notice.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyToast.showDefaltToast("基本版不支持自定义各分区业态及参数，高级版无此限制。升级说明请参见菜单中的关于页面");
            }
        });
        return view;
    }

    public void show() {
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());  //先得到构造器
        builder.setTitle("提示"); //设置标题
        builder.setMessage("获取项目列表"); //设置内容
        builder.setCancelable(false);
        dialog = builder.create();
        dialog.show();
        Map<String, String> map = new HashMap<>();
        map.put("bldgId", MyprojectActivity.currentProjectModel.bldgId);
        TaskEngine.getInstance().startGetAreaTask(queue, map, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject json) {
                LogUtils.e("获取项目列表" + "sec" + json.toString());
                try {
//                    String j = "{\"respCode\":\"OK\",\"respNo\":\"200\",\"level\":0,\"respDesc\":\"获取数据成功!\",\"list\":[{\"createAt\":1466086132000,\"areaId\":263,\"bldgId\":2016061422122232,\"planId\":206,\"areaName\":\"办公1区\",\"floorBottom\":1,\"floorTop\":10,\"type\":4,\"areaGrade\":1,\"skyLobby\":1,\"floorHeight\":30,\"floorValue\":30,\"liftSpeed\":1,\"liftLoad\":1,\"liftNum\":1,\"areaIndex\":0,\"persionRatio\":0.2},{\"createAt\":1466086132000,\"areaId\":263,\"bldgId\":2016061422122232,\"planId\":206,\"areaName\":\"办公2区\",\"floorBottom\":10,\"floorTop\":30,\"type\":5,\"areaGrade\":1,\"skyLobby\":1,\"floorHeight\":3,\"floorValue\":10,\"liftSpeed\":1,\"liftLoad\":1,\"liftNum\":1,\"areaIndex\":1,\"persionRatio\":2.1},{\"createAt\":1466086132000,\"areaId\":263,\"bldgId\":2016061422122232,\"planId\":206,\"areaName\":\"办公3区\",\"floorBottom\":30,\"floorTop\":40,\"type\":6,\"areaGrade\":1,\"skyLobby\":1,\"floorHeight\":4,\"floorValue\":8,\"liftSpeed\":1,\"liftLoad\":1,\"liftNum\":1,\"areaIndex\":2,\"persionRatio\":4.1},{\"createAt\":1466086132000,\"areaId\":263,\"bldgId\":2016061422122232,\"planId\":206,\"areaName\":\"办公4区\",\"floorBottom\":50,\"floorTop\":70,\"type\":6,\"areaGrade\":1,\"skyLobby\":1,\"floorHeight\":10,\"floorValue\":11,\"liftSpeed\":1,\"liftLoad\":1,\"liftNum\":1,\"areaIndex\":3,\"persionRatio\":9.12},{\"createAt\":1466086133000,\"areaId\":264,\"bldgId\":2016061422122232,\"planId\":207,\"areaName\":\"办公区1\",\"floorBottom\":10,\"floorTop\":40,\"type\":5,\"areaGrade\":1,\"skyLobby\":1,\"floorHeight\":1,\"floorValue\":1,\"liftSpeed\":1,\"liftLoad\":1,\"liftNum\":1,\"areaIndex\":0,\"persionRatio\":9.1},{\"createAt\":1466086133000,\"areaId\":264,\"bldgId\":2016061422122232,\"planId\":207,\"areaName\":\"办公区3\",\"floorBottom\":60,\"floorTop\":80,\"type\":4,\"areaGrade\":1,\"skyLobby\":1,\"floorHeight\":1,\"floorValue\":1,\"liftSpeed\":1,\"liftLoad\":1,\"liftNum\":1,\"areaIndex\":2,\"persionRatio\":0.2},{\"createAt\":1466086133000,\"areaId\":264,\"bldgId\":2016061422122232,\"planId\":207,\"areaName\":\"办公区2\",\"floorBottom\":40,\"floorTop\":50,\"type\":5,\"areaGrade\":1,\"skyLobby\":1,\"floorHeight\":1,\"floorValue\":1,\"liftSpeed\":1,\"liftLoad\":1,\"liftNum\":1,\"areaIndex\":1,\"persionRatio\":2.1}],\"bldgPlanlist\":[{\"createAt\":1466086132000,\"bldgId\":2016061422122232,\"planAreaNum\":4,\"planId\":206},{\"createAt\":1466086132000,\"bldgId\":2016061422122232,\"planAreaNum\":3,\"planId\":207}]}";
//                    json = new JSONObject(j);
                    String respCode = json.getString("respCode");
                    if (!StringUtil.equal(respCode, "OK")) {
                        try {
                            if (json.getInt("respNo") == 999) {
                                LoginOut.LoginOut(getActivity());
                            }
                        } catch (Exception e) {
                            MyToast.showDefaltToast("获取数据失败");
                        }
                    } else {
                        planModel = new PlanModel(json);
                        areaArrayList_Copy = new Gson().fromJson(json.getJSONArray("list").toString(), new TypeToken<List<PlanModel.Area>>() {
                        }.getType());
                        Collections.sort(planModel.planArrayList);
                        arr1 = planModel.getPlanNumList();
                        if (CURRENT_PLAN == -1) {
                            init2();
                            if (planModel.planArrayList != null && planModel.planArrayList.size() != 0) {
                                setPlan(planModel.planArrayList.get(0));
                            }
                            CURRENT_PLAN = 0;
                        } else {
                            init2();
                            informationSpinner.setSelection(CURRENT_PLAN);
                            if (planModel.planArrayList != null && planModel.planArrayList.size() != 0) {
                                setPlan(planModel.planArrayList.get(CURRENT_PLAN));
                            }
                        }
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (dialog != null) {
                    dialog.dismiss();
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        });
        partInformationName.setText(MyprojectActivity.currentProjectModel.bldgName);
    }

    private void setPlan(PlanModel.Plan plan) {
        areaArrayListOfPlan = planModel.getAreaArrayListByPlanId(plan.planId);
        Collections.sort(areaArrayListOfPlan);
        if (areaArrayListOfPlan.size() != 0) {
            textViews.add(fenquText1);
            textViews.add(fenquText2);
            textViews.add(fenquText3);
            textViews.add(fenquText4);
            for (TextView textView : textViews) {
                textView.setVisibility(View.INVISIBLE);
            }
            dragGroups.setView(areaArrayListOfPlan, MyprojectActivity.currentProjectModel.bldgFloors);
            dragGroups.setViewSelected(0);
            for (int i = 0; i < areaArrayListOfPlan.size(); i++) {
                PlanModel.Area area = areaArrayListOfPlan.get(i);
                textViews.get(i).setText(area.areaName);
                textViews.get(i).setVisibility(View.VISIBLE);
                dragGroups.setSkyLobby(i, area.isSkyLobby());
            }
            currentIndex = 0;
            setData(areaArrayListOfPlan.get(0));
            String typeName = DictionaryModel.getInstance().getTypeByTypeId(areaArrayListOfPlan.get(0).type).typeName;
            initSpinner(typeName);
        }
    }

    private void setData(PlanModel.Area area) {
        String typeName = DictionaryModel.getInstance().getTypeByTypeId(area.type).typeName;
        jibenName.setText(area.areaName);
        checkbox.setChecked(area.isSkyLobby());
        if (DictionaryModel.getInstance().getTypeByTypeId(area.type) == null) {
            MyToast.showDefaltToast("数据格式错误");
            return;
        }
        line1_middle.setText(area.floorValue + "");
        line2_middle.setText(area.targetPerson + "");
        line3_middle.setText(area.persionRatio + "");
        if (typeName.equalsIgnoreCase("酒店")) {
            line1_left.setText("客房数：");
            line2_left.setText("每客房人数：");
            line3_left.setText("入住率：");
            line1_right.setText("房间/层");
            line2_right.setText("人/房间");
            line3_right.setText("%");
        } else if (typeName.equalsIgnoreCase("办公")) {
            line1_left.setText("建筑面积：");
            line2_left.setText("人均面积：");
            line3_left.setText("出勤率：");
            line1_right.setText("平方米/层");
            line2_right.setText("平方米/人");
            line3_right.setText("%");
        } else if (typeName.equalsIgnoreCase("住宅")) {
            line1_left.setText("建筑面积：");
            line2_left.setText("人均面积：");
            line3_left.setText("入住率：");
            line1_right.setText("平方米/层");
            line2_right.setText("平方米/人");
            line3_right.setText("%");
        }
    }

    private void setParm() {
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) dragview.getLayoutParams();
        params.height = screen_height / 2;
        dragGroups.setViewCount(4, true);
        dragGroups.setViewSelected(0);
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.reset(this);
    }

    private ArrayList<PlanModel.Area> changeAreas = new ArrayList<>();
    private boolean isGo = false;

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.iv_bottome_left:
                isGo = false;
                changeAreas.clear();
                for (PlanModel.Area area : planModel.areaArrayList) {
                    for (PlanModel.Area area_copy : areaArrayList_Copy) {
                        if (area_copy.areaId.equalsIgnoreCase(area.areaId)) {
                            if (area_copy.floorBottom != area.floorBottom || !area_copy.areaName.equalsIgnoreCase(area.areaName) || area_copy.floorTop != area.floorTop
                                    || area_copy.type != area.type || area_copy.areaGrade != area.areaGrade || area_copy.skyLobby != area.skyLobby || area_copy.floorHeight != area.floorHeight
                                    || area_copy.floorValue != area.floorValue || area_copy.persionRatio != area.persionRatio || area_copy.targetPerson != area.targetPerson) {
                                changeAreas.add(area);
                            }
                            break;
                        }
                    }
                }
                if (changeAreas.size() != 0) {
                    for (PlanModel.Area area : changeAreas) {
                        updateArea(area);
                    }
                } else {
                    EventBus.getDefault().post(new BusAction.myMess());
                }
                break;
            case R.id.iv_bottome_right:
                isGo = true;
                changeAreas.clear();
                for (PlanModel.Area area : planModel.areaArrayList) {
                    for (PlanModel.Area area_copy : areaArrayList_Copy) {
                        if (area_copy.areaId.equalsIgnoreCase(area.areaId)) {
                            if (area_copy.floorBottom != area.floorBottom || !area_copy.areaName.equalsIgnoreCase(area.areaName) || area_copy.floorTop != area.floorTop
                                    || area_copy.type != area.type || area_copy.areaGrade != area.areaGrade || area_copy.skyLobby != area.skyLobby || area_copy.floorHeight != area.floorHeight
                                    || area_copy.floorValue != area.floorValue || area_copy.persionRatio != area.persionRatio || area_copy.targetPerson != area.targetPerson) {
                                changeAreas.add(area);
                            }
                            break;
                        }
                    }
                }
                if (changeAreas.size() != 0) {
                    for (PlanModel.Area area : changeAreas) {
                        updateArea(area);
                    }
                } else {
                    EventBus.getDefault().post(new BusAction.mymessDianti());
                }
                break;
        }
    }

    private void updateArea(final PlanModel.Area area) {
        HashMap<String, String> map = new HashMap<>();
        map.put("areaId", area.areaId);
        map.put("bldgId", area.bldgId);
        map.put("planId", area.planId);
        map.put("areaName", area.areaName);
        map.put("floorBottom", area.floorBottom + "");
        map.put("floorTop", area.floorTop + "");
        map.put("type", area.type + "");
        map.put("areaGrade", area.areaGrade + "");
        map.put("skyLobby", area.skyLobby + "");
        map.put("floorHeight", area.floorHeight + "");
        map.put("floorValue", area.floorValue + "");
        map.put("targetPerson", area.targetPerson + "");
        map.put("liftSpeed", area.liftSpeed + "");
        map.put("liftLoad", area.liftLoad + "");
        map.put("liftNum", area.liftNum + "");
        map.put("persionRatio", area.persionRatio + "");
        TaskEngine.getInstance().startUpdateAreaTask(queue, map, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject json) {
                try {
                    String respCode = json.getString("respCode");
                    if (!StringUtil.equal(respCode, "OK")) {
                        try {
                            if (json.getInt("respNo") == 999) {
                                LoginOut.LoginOut(getActivity());
                            }
                        } catch (Exception e) {
                            MyToast.showDefaltToast("获取数据失败");
                        }
                    } else {
                        changeAreas.remove(area);
                        if (changeAreas.size() == 0) {
                            MyToast.showDefaltToast(json.getString("respDesc"));
                            if (isGo) {
                                EventBus.getDefault().post(new BusAction.mymessDianti());
                            } else {
                                EventBus.getDefault().post(new BusAction.myMess());
                            }
                        }
                    }
                } catch (Exception e) {
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {

            }
        });
    }

    private void init2() {
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, arr1) {
            @Override
            public View getDropDownView(int position, View convertView,
                                        ViewGroup parent) {
                View view = LayoutInflater.from(getContext()).inflate(R.layout.item_spinner,
                        null);
                TextView label = (TextView) view
                        .findViewById(R.id.spinner_item_label);
                label.setText(arr1.get(position) + "");
                return view;
            }
        };
//        arrayAdapter.setDropDownViewResource(R.layout.item_spinner);
        //设置显示的数据

        informationSpinner.setAdapter(arrayAdapter);

        //注册事件
        informationSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                                       int position, long id) {
                informationSpinner.setDropDownVerticalOffset(informationSpinner.getHeight());
                setPlan(planModel.planArrayList.get(position));
                CURRENT_PLAN = position;
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }

        });
//        informationSpinner1.setAdapter(arrayAdapter);
//
//        //注册事件
//        informationSpinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
//
//            @Override
//            public void onItemSelected(AdapterView<?> parent, View view,
//                                       int position, long id) {
//                informationSpinner1.setDropDownVerticalOffset(informationSpinner1.getHeight());
//            }
//
//            @Override
//            public void onNothingSelected(AdapterView<?> parent) {
//            }
//
//        });
    }

    private int currentIndex = 0;

    @Subscribe
    public void onEventMainThread(BusAction.PartInfoDragViewClicked event) {
        dragGroups.setViewSelected(event.index);
        currentIndex = event.index;
        areaArrayListOfPlan.get(currentIndex).floorBottom = event.floorBottom;
        areaArrayListOfPlan.get(currentIndex).floorTop = event.floorTop;
        setData(areaArrayListOfPlan.get(currentIndex));
        String typeName = DictionaryModel.getInstance().getTypeByTypeId(areaArrayListOfPlan.get(currentIndex).type).typeName;
        initSpinner(typeName);
    }

    // 订阅事件DataChangedEvent
    public void setCardEvent(DataChangedEvent event) {

        switch (event.getAction()) {
            case BusAction.MYMESS_CLICK:
                dragGroups.setViewSelected(event.getCode());
                currentIndex = event.getCode();
                setData(areaArrayListOfPlan.get(currentIndex));
                break;
        }
    }
}
